package com.shycloud.mido.organ.api.util;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class YMDTools {

	public final static SimpleDateFormat uid1 = new SimpleDateFormat("yyyyMMdd");
	public final static SimpleDateFormat uid2 = new SimpleDateFormat("yyMMddHHmmssSS");
	public final static SimpleDateFormat uid3 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	public final static SimpleDateFormat uid4 = new SimpleDateFormat("yyyy-MM-dd");
	public final static SimpleDateFormat uid5 = new SimpleDateFormat("HH:mm:ss");
	public final static SimpleDateFormat uid6 = new SimpleDateFormat("yyyy-MM");
	
	public static String currentTimestamp(){
	    String  uuid =uid2.format(Calendar.getInstance().getTime()).toString();
		return uuid;
	}
	
	public static String currentDateTime(){
	    String  uuid =uid3.format(Calendar.getInstance().getTime()).toString();
		return uuid;
	}
	
	public static String currentDate(){
	    String  uuid =uid4.format(Calendar.getInstance().getTime()).toString();
		return uuid;
	}
	public static String currentMonth(){
	    String  uuid =uid6.format(Calendar.getInstance().getTime()).toString();
		return uuid;
	}


	/**
	 * @Title: strToDate
	 * @Description: TODO(字符串转DATE类型)
	 * @param @param str
	 * @param @return    设定文件
	 * @return Date    返回类型
	 * @throws
	 */
	public static Date strToDate(SimpleDateFormat sdf,String date0){

		try {
			Date date = sdf.parse(date0);
			return date;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return  null;
	}
	
	/** 
	* @Title: dateToStr 
	* @Description: TODO(date类型转到 字符串) 
	* @param @param sdf
	* @param @param date
	* @param @return    设定文件 
	* @return String    返回类型 
	* @throws 
	*/ 
	public static String dateToStr(SimpleDateFormat sdf,Date date){
		String str=sdf.format(date);  
		return str;
	}

	/**
	 * @param @param  str
	 * @param @return 设定文件
	 * @return Date    返回类型
	 * @throws
	 * @Title: strToDate
	 * @Description: TODO(字符串转DATE类型)
	 */
	public static Date timestampToDate(String date0) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
		try {
			Date date = sdf.parse(date0);
			return date;
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}


	/**
	 * @Title: currentDate
	 * @Description: TODO(获取当前时间字符串类型)
	 * @param @param i
	 * @param @return    设定文件
	 * @return String    返回类型
	 * @throws
	 */
	public static String currentDate(int i){
		String[] format = new String[]{"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd"};
		SimpleDateFormat dateFormat = new SimpleDateFormat(format[i]);
		Date date = new Date();
		return dateFormat.format(date);
	}
	/**
	 * @Title: currentDate
	 * @Description: TODO(获取当前时间字符串类型)
	 * @param @param i
	 * @param @return    设定文件
	 * @return String    返回类型
	 * @throws
	 */
	public static String formatDate(int i,Date date){
		String[] format = new String[]{"yyyy-MM-dd HH:mm:ss","yyyy-MM-dd"};
		SimpleDateFormat dateFormat = new SimpleDateFormat(format[i]);
		return dateFormat.format(date);
	}
	
	
	
	/**  
	* @Title: JudgeTime  計算時間差
	* @Description: TODO
	* @param @param date
	* @param @return
	* @return Map<String,Long>
	* @throws  
	*/
	public static  Map<String, Long> judgeTime(Date date){
		
		
		Map<String, Long> map = new HashMap<>();
		try {
			Date nowDate = new Date();//获取当前时间
			long diff = nowDate.getTime() - date.getTime();//这样得到的差值是毫秒级别
			//System.out.println("【时间规则,输入的时间距离实时时间相聚多少毫秒：】"+diff);
			
			//计算得到时分秒
		    long days = diff / (1000 * 60 * 60 * 24);	 
		    long hours = (diff-days*(1000 * 60 * 60 * 24))/(1000* 60 * 60);
		    long minutes = (diff-days*(1000 * 60 * 60 * 24)-hours*(1000* 60 * 60))/(1000* 60);
		    //System.out.println("【通过计算得到输入时间距离当前时间相差多少，天，时，分：】"+days+"天"+hours+"小时"+minutes+"分");
		    
		    map.put("day", days);
		    map.put("hour", hours);
		    map.put("minute", minutes);
		} catch (Exception e) {
			//System.out.println("【通过计算得到输入时间距离当前时间相差多少，天，时，分：】"+e);
		}
		return map;	
	}


	public static long dateToStamp(String s) {
		String res;
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = null;
		try {
			date = simpleDateFormat.parse(s);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		long ts = date.getTime();
		return ts;
	}

	public static void main(String args[]){
		System.out.println(currentDateTime());
	}
}
